<?php
/**
 * Description: 微信小程序解密支持
 * User: devforma
 * Date: 2016/11/24
 * Time: 17:02
 */

require __DIR__.'/library/wxBizDataCrypt.php';

class WeixinAppDecode implements iController {

    /**
     * api请求处理主函数
     * @param array $queryArgs 就是$_REQUEST变量
     * @return array api返回结果，必须含response_code
     */
    public function output($queryArgs) {
        if(!empty($queryArgs['appid']) && !empty($queryArgs['sessionKey']) && !empty($queryArgs['encryptedData']) && !empty($queryArgs['iv'])){
            $pc = new WXBizDataCrypt($queryArgs['appid'], $queryArgs['sessionKey']);
            $errCode = $pc->decryptData($queryArgs['encryptedData'], $queryArgs['iv'], $data );
            if($errCode == 0){
                $data = json_decode($data,true);
                return genOutput(1, ['data_encode' => $data]);
            }else{
                return genOutput(1000);
            }
        }else{
            return genOutput(1000);
        }
    }
}